home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / xwinc100.zip / CONTRIB-.00 / CONTRIB- / contrib / examples / PEX / picktest.c < prev    next >
C/C++ Source or Header  |  1991-02-16  |  5KB  |  186 lines

  1. /* $XConsortium: picktest.c,v 5.1 91/02/16 09:32:28 rws Exp $ */
  2.  
  3. /***********************************************************
  4. Copyright (c) 1991 by Sun Microsystems, Inc. and the X Consortium.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Sun Microsystems,
  13. the X Consortium, and MIT not be used in advertising or publicity 
  14. pertaining to distribution of the software without specific, written 
  15. prior permission.  
  16.  
  17. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  19. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  20. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26.  
  27. /**
  28. ***  Sample pick program to test picking of polylines, polymarkers,
  29. ***  text and annotation text.
  30. ***/
  31.  
  32. #include "phigs/phigs.h"
  33.  
  34. static Plimit viewport = {100.0,500.0,100.0,500.0};
  35. static Ppoint points[5] = {0.01,0.01, 0.01,0.99, 0.99,0.99, 0.99,0.01, 0.01,0.01};
  36. static Ppoint_list line, markers;
  37. static Ppoint mpoints[5] = {0.21,0.21, 0.23,0.23, 0.26,0.26, 0.24,0.20, 0.30,0.24};
  38. static Ppoint torigins[] = {0.1,0.1, 0.5,0.5, 0.1,0.8, 0.8,0.1, 0.9,0.9};
  39. static Ppoint3 txpta = {0.5,0.5,0.0};
  40. static Pvec3 txdir[2] = {1.0, 0.0, 0.0,
  41.              0.0, 1.0, 0.0};
  42. static Ppoint3 txpt2 = {0.2,0.2,0.0};
  43. static Ppoint3 offset2 = {-0.2,0.4,0.0};
  44. static Ppoint txpt3 = {0.5,0.5};
  45. static Ppoint offset3 = {-0.2,-0.2};
  46. static   Plimit            ea={100.0, 500.0, 100.0, 500.0 };
  47.  
  48. main( argc, argv )
  49.     int        argc;
  50.     char    *argv[];
  51. {
  52.     Pin_status        status;
  53.     Pint        pet, err, names[5];
  54.     Ppick_data          drec;   
  55.     Ppick_path        path;
  56.     Ppick_path_elem     path_els[2];  
  57.     Pfilter        filt;
  58.     int                 i;
  59.  
  60.     /* Set up line */
  61.  
  62.     line.num_points = 5;
  63.     line.points = &points[0];
  64.  
  65.     /* Set up markers */
  66.  
  67.     markers.num_points = 5;
  68.     markers.points = &mpoints[0];
  69.  
  70.     /* Initialize PHIGS and start up */
  71.  
  72.     popen_phigs( (char *)NULL, PDEF_MEM_SIZE );
  73.  
  74.     /* Build the CSS */
  75.  
  76.     popen_struct( 1 );
  77.     plabel( 3 );
  78.     pset_pick_id( 5 );
  79.     pexec_struct( 2 );
  80.     pclose_struct();
  81.     popen_struct( 2 );
  82.     names[0] = 1;
  83.     filt.incl_set.num_ints = 1;
  84.     filt.incl_set.ints = names;
  85.     padd_names_set( &filt.incl_set );
  86.  
  87.         pset_line_colr_ind(2);  /* Set the line color to red */
  88.     ppolyline( &line );     /* #3 */
  89.  
  90.     pset_pick_id( 10 );
  91.         pset_marker_colr_ind(7);  /* Set the marker color to magenta */
  92.         pset_marker_size(2.0);
  93.     ppolymarker( &markers );  /* #7 */
  94.  
  95.     pset_pick_id( 20 );
  96.     pset_text_colr_ind (5);
  97.     pset_char_expan (-2.0);
  98.         ptext(&torigins[0], "PEX-SI's 2D Text can be PICKED !");  /* #11 */
  99.  
  100.     pset_pick_id( 30 );
  101.         pset_text_path (PPATH_UP);  
  102.     pset_char_ht (0.02);
  103.     pset_text_colr_ind (1);
  104.         ptext3(&txpta,txdir,"3D Text PICK TEST");  /* #16 */
  105.     pset_line_colr_ind(6);
  106.  
  107.     pset_pick_id( 40 );
  108.     pset_linetype (3);
  109.         pset_anno_path (PPATH_RIGHT);  
  110.     pset_anno_char_ht (-0.020);
  111.     pset_anno_style (2);
  112.     pset_text_colr_ind (6);
  113.         panno_text_rel(&txpt3,&offset3,"Testing Anno2D Text Picking");/* #24 */
  114.  
  115.     pset_pick_id( 50 );
  116.     pset_anno_char_ht (-0.015);
  117.     pset_char_expan (-2.0);
  118.     pset_anno_style (1);
  119.     pset_text_colr_ind (3);
  120.         panno_text_rel3(&txpt2,&offset2,"Picking Anno3D Text"); /* #30 */
  121.     pclose_struct();
  122.  
  123.     /* Open a X-tool workstation */
  124.  
  125.     popen_ws( 1, (char *)NULL, phigs_ws_type_x_tool );
  126.     pset_ws_vp( 1, &viewport );
  127.  
  128.     /* Post the structure */
  129.  
  130.     ppost_struct( 1, 1, 1.0 );
  131.  
  132.     /* Make everything detectable */
  133.  
  134.     if (argc == 1) {
  135.     names[0] = 1;
  136.     filt.incl_set.num_ints = 1;
  137.     filt.incl_set.ints = names;
  138.     filt.excl_set.num_ints = 0;
  139.     filt.excl_set.ints = (Pint *)NULL;
  140.     pset_pick_filter( 1, 1, &filt );
  141.  
  142.     /* Initialize and enable the Pick device */
  143.  
  144.     path.depth = 0;
  145.     path.path_list = path_els;
  146.     pet = 1;
  147.     pinit_pick( 1, 1, PIN_STATUS_NONE, &path, pet, &ea, &drec, PORDER_TOP_FIRST );
  148.     pset_pick_mode( 1, 1, POP_REQ, PSWITCH_NO_ECHO );
  149.  
  150.     /* Set up a Picking Loop */
  151.  
  152.     printf ("Type '^c' to quit; else keep picking:\n");
  153.     while (1) {
  154.  
  155.         /* Request Pick */
  156.  
  157.         status = PIN_STATUS_NONE;
  158.         preq_pick(1, 1, 2, &status, &path);
  159.  
  160.         /* Check if anything got picked; if so, print it */
  161.  
  162.         if (status == PIN_STATUS_OK) {
  163.         printf ("Path depth = %d\n", path.depth);
  164.         for (i=0; i<path.depth; i++) {
  165.             printf ("Structure ID = %d\n", path.path_list[i].struct_id);
  166.             printf ("Pick ID = %d\n", path.path_list[i].pick_id);
  167.             printf ("Element Number = %d\n", path.path_list[i].elem_pos);
  168.         }
  169.         printf ("\n");
  170.         }
  171.         else {
  172.         printf ("Nothing detected ! !\n");
  173.         printf ("\n");
  174.         }
  175.     }
  176.     }
  177.  
  178.     /* Close up */
  179.  
  180.     pclose_ws( 1 );
  181.     pclose_phigs();
  182. }
  183.  
  184.  
  185.  
  186.